//	ID : pallab81
// 	PROG : 10336
// 	LANG : C++
// 	2011-07-06-19.50.40 Wednesday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long

int mov[4][2]={{-1,0},{+1,0},{0,+1},{0,-1}};
int vis[30];
int grid[30][30];
int row, col;

inline void print(){
    for(int r=0;r<row;++r){
        for(int c=0;c<col;++c){
            cout<<grid[r][c]<<"\t";
        }
        printf("\n");
    }
    //bip;
}

inline void read(){
        scanf("%d %d",&row,&col);
        for(int i=0;i<row;++i){
            for(int j=0;j<col;++j){
                char ch;
                cin>>ch;
                grid[i][j] = ch-'a';
            }
        }
}
inline void fill(int r, int c, int x){
    stack< pair<int,int> > st;
    grid[r][c]=-1;
    st.push( make_pair(r,c) );

    while( st.empty()==false ){
        pair<int,int> peak = st.top();
        st.pop();
        for(int i=0;i<4;++i){
            int tr = mov[i][0]+peak.first;
            int tc = mov[i][1]+peak.second;
            if(tr <0 || tc < 0 || tr >= row || tc >=col ){
                continue;
            }
            if( grid[tr][tc]==x ){
                grid[tr][tc]=-1;
                st.push( make_pair(tr,tc) );
            }

        }
    }
}
inline bool cmp(pair<int,int> A, pair<int,int> B){
    if( A.first==B.first ){
        return A.second<B.second;
    }
return A.first > B.first;
}
inline void proc(int cases){
    memset(vis,0,sizeof(vis));
    int r,c;
    for(r=0;r<row;++r){
        for(c=0;c<col;++c){
            if( grid[r][c]!=-1 ){
                vis[ grid[r][c] ]++;
                fill(r,c, grid[r][c]);
                //print();
            }
        }
    }
    vector< pair<int,char> > vt;
    for(int i=0;i<26;++i){
        if( vis[i]!=0 ){
            vt.push_back( make_pair(vis[i], (char)'a'+i) );
        }
    }
    sort(vt.begin(),vt.end(), cmp );

    printf("World #%d\n",cases);
    for(int i=0;i<(int)vt.size();++i){
        printf("%c: %d\n",vt[i].second,vt[i].first);
    }
}

int main(){
    int cases;
    scanf("%d",&cases);
    for(int i=1; i<=cases;++i){
        read();
        proc();
    }

return 0;
}

